package org.wdcode.core.concurrent;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.wdcode.core.factory.BaseFactory;
import org.wdcode.core.params.WdCoreParams;

/**
 * Executor JDK新线程实现 的工厂
 * @author WD
 * @since JDK6
 * @version 1.0 2010-01-26
 */
public final class ExecutorFactory extends BaseFactory<ExecutorService> {
	// 工厂
	private final static ExecutorFactory	FACTORY;

	/**
	 * 静态初始化
	 */
	static {
		FACTORY = new ExecutorFactory();
	}

	/**
	 * 返回工厂
	 * @return 工厂
	 */
	public final static ExecutorFactory getFactory() {
		return FACTORY;
	}

	/**
	 * 新生成一个线程池 线程池大小自动分配
	 * @return ExecutorService
	 */
	public ExecutorService newInstance() {
		return newInstance(WdCoreParams.getThreadSize());
	}

	/**
	 * 新生成一个线程池
	 * @param size 线程个数
	 * @return ExecutorService
	 */
	public ExecutorService newInstance(int size) {
		return Executors.newFixedThreadPool(size);
	}
}
